//
//  DUMonthButton.swift
//  SimpleCal
//
//  Created by 杜晓祥 on 2021/10/21.
//

import Cocoa

@IBDesignable
class DUMonthButton: BaseView {
    
    var monthLabel: DULabel!
    
    convenience init() {
        self.init(frame: CGRect.zero)
    }

    override init(frame frameRect: NSRect) {
        super.init(frame: frameRect)
        initialize()
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
        initialize()
    }
    
    private func initialize () {
        self.mouseDownStyle = getDownStyle()
        self.mouseEnteredStyle = getEnteredStyle()
        self.defaultStyle = ViewStyleUtil.dayDefaultStyle()
        monthLabel = DULabel()
        let w = self.frame.width
        monthLabel.frame = NSRect(x: 5, y: 5, width: w - 10, height: 30)
        monthLabel.font = NSFont.systemFont(ofSize: 25)
        addSubview(monthLabel)
    }
    
    override func layout() {
        super.layout()
        let w = self.frame.width
        monthLabel.setFrameSize(NSSize(width: w - 10, height: 30))
    }
    
    func stringValue(_ value:String) {
        monthLabel.stringValue = value
    }
    
    private func getDownStyle() -> ViewStyle {
        var s = ViewStyle()
        s.backgroundColor = CGColor(red: 255, green: 255, blue: 255, alpha: 0.4)
        s.borderColor = nil
        s.borderWidth = 0
        s.radius = 8
        return s
    }
    
    private func getEnteredStyle() -> ViewStyle {
        var s = ViewStyle()
        s.backgroundColor = CGColor(red: 255, green: 255, blue: 255, alpha: 0.2)
        s.borderColor = nil
        s.borderWidth = 0
        s.radius = 8
        return s
    }
}
